package cn.mall.framework.common;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonKit {

	public static Object[] jsonToArray(String json) {
		JSONArray jSONArray = JSONArray.fromObject(json);
		return jSONArray.toArray();

	}

	public static String array2json(Object[] obj) {
		JSONArray j = JSONArray.fromObject(obj);
		return j.toString();
	}

	@SuppressWarnings("unchecked")
	public static Map<String, String> jsonToMap(String json) {
		Map<String, String> classMap = new HashMap<String, String>();
		Map<String, String> map = (Map<String, String>) JSONObject.toBean(
				JSONObject.fromObject(json), Map.class, classMap);
		return map;
	}

	public static String map2json(Map<String, String> map) {
		JSONObject j = JSONObject.fromObject(map);
		return j.toString();
	}

	public static void main(String[] args) {
		Map<String, String> xx = jsonToMap("{'x':'1'}");
		System.out.println(xx);
		 Object[] obj
		 =jsonToArray("['01','800','20071117020101','123','','','123345','dfsadfasdfsa','11111111111','345555']");
		 System.out.println(obj[0]);
		/*String[] strs= new String[2];
		strs[0]="aa";
		strs[1]="bb";
		System.out.println(array2json(strs));*/
		// Map map = new HashMap();
		// map.put("aaaaa", "aaaaaa");
		// map.put("bbbbb", "bbbbbb");
		// System.out.println(JsonUtil.map2json(map));

	}
}
